package com.github.admin.edu.oauth.server.api.hystris;

import com.github.admin.edu.assembly.common.entity.JsonEntity;
import com.github.admin.edu.assembly.common.util.JsonUtils;
import com.github.admin.edu.oauth.server.api.entity.TokenEntity;
import com.github.admin.edu.oauth.server.api.service.ServiceOAuthServiceApi;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 * user:wangj
 * date:2018/7/18
 * Time: 21:29
 */
@Component
public class ServiceOAuthServiceHystris implements FallbackFactory<ServiceOAuthServiceApi> {
    @Override
    public ServiceOAuthServiceApi create(Throwable throwable) {
        return new ServiceOAuthServiceApi() {
            @Override
            public String getServiceToken(String clientId) {
                return JsonUtils.toJson(new JsonEntity<TokenEntity>("服务端异常，无法连接！"));
            }

            @Override
            public String authToken(String clientId,String serverId,String token) {
                return JsonUtils.toJson(new JsonEntity<TokenEntity>("服务端异常，无法连接！"));
            }
        };
    }
}
